package com.tuozixuan.jmh.me;

import java.util.concurrent.TimeUnit;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Measurement(iterations = 3, time = 100, timeUnit = TimeUnit.MILLISECONDS)
@Warmup(iterations = 3, time = 100, timeUnit = TimeUnit.MILLISECONDS)
public class BitwiseOperation {

	@Benchmark
	public void bitOperation(Blackhole bh) {
		bh.consume(1 << 30);
	}
	
	@Benchmark
	public void powOperation (Blackhole bh) {
		bh.consume(Math.pow(2, 30));
	}
	
	public static void main(String[] args) throws RunnerException {
		Options opt = new OptionsBuilder().include(BitwiseOperation.class.getSimpleName()).forks(1).build();
		new Runner(opt).run();
	}
}
